package com.flyduck.vueshop.system.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.flyduck.vueshop.common.core.lang.Result;
import com.flyduck.vueshop.system.admin.service.AdminMenuService;
import com.flyduck.vueshop.system.admin.vo.AdminMenuDetailsRespVO;
import com.flyduck.vueshop.system.admin.vo.AdminMenuSaveReqVO;
import com.flyduck.vueshop.system.admin.vo.AdminMenuTreeRespVO;
import com.flyduck.vueshop.system.admin.vo.AdminMenuUpdateReqVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * SysMenuController
 * </p>
 *
 * @author flyduck
 * @since 2024-06-03
 */
@RestController
@RequestMapping("/system/admin/menu")
public class AdminMenuController {

    @Resource
    private AdminMenuService adminMenuService;

    @GetMapping("/getMenuTree")
    @SaCheckPermission("sys:menu:list")
    public Result<List<AdminMenuTreeRespVO>> getMenuTree(){
        List<AdminMenuTreeRespVO> adminMenuTreeRespVOList = adminMenuService.getMenuTree();
        return Result.success(adminMenuTreeRespVOList);
    }

    @GetMapping("/getMenuDetailsById/{id}")
    @SaCheckPermission("sys:menu:list")
    public Result<AdminMenuDetailsRespVO> getMenuDetailsById(@PathVariable("id") Long id){
        AdminMenuDetailsRespVO adminMenuDetailsRespVO = adminMenuService.getMenuDetailsById(id);
        return Result.success(adminMenuDetailsRespVO);
    }

    @PostMapping("/saveMenu")
    @SaCheckPermission("sys:menu:save")
    public Result<Void> saveMenu(@Validated @RequestBody AdminMenuSaveReqVO adminMenuSaveReqVO){
        adminMenuService.saveMenu(adminMenuSaveReqVO);
        return Result.success();
    }

    @PostMapping("/updateMenu")
    @SaCheckPermission("sys:menu:update")
    public Result<Void> updateMenu(@Validated @RequestBody AdminMenuUpdateReqVO adminMenuUpdateReqVO){
        adminMenuService.updateMenu(adminMenuUpdateReqVO);
        return Result.success();
    }

    @PostMapping("/deleteById/{id}")
    @SaCheckPermission("sys:menu:delete")
    public Result<Void> deleteById(@PathVariable("id") Long id){
        adminMenuService.deleteById(id);
        return Result.success();
    }

}
